VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{8E27C92E-1264-101C-8A2F-040224009C02}#7.0#0"; "MSCAL.OCX"
Begin VB.Form frmTD 
   BackColor       =   &H00FFFFFF&
   Caption         =   "TD Shipments"
   ClientHeight    =   3420
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8175
   Icon            =   "frmTD.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   3420
   ScaleWidth      =   8175
   StartUpPosition =   1  'CenterOwner
   Begin VB.Timer timerAutoClose 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   6600
      Top             =   2400
   End
   Begin VB.Timer timerMaster 
      Enabled         =   0   'False
      Interval        =   300
      Left            =   6840
      Top             =   2400
   End
   Begin VB.Timer timerUpdate 
      Enabled         =   0   'False
      Interval        =   200
      Left            =   7080
      Top             =   2400
   End
   Begin VB.CommandButton cmdDupTD 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0E0FF&
      Caption         =   "Add by Dup."
      Height          =   315
      Left            =   1950
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   2925
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin MSACAL.Calendar Calendar1 
      Height          =   315
      Left            =   375
      TabIndex        =   9
      TabStop         =   0   'False
      Top             =   525
      Visible         =   0   'False
      Width           =   315
      _Version        =   524288
      _ExtentX        =   556
      _ExtentY        =   556
      _StockProps     =   1
      BackColor       =   16777215
      Year            =   2004
      Month           =   2
      Day             =   9
      DayLength       =   1
      MonthLength     =   2
      DayFontColor    =   0
      FirstDay        =   1
      GridCellEffect  =   1
      GridFontColor   =   10485760
      GridLinesColor  =   -2147483632
      ShowDateSelectors=   -1  'True
      ShowDays        =   -1  'True
      ShowHorizontalGrid=   -1  'True
      ShowTitle       =   0   'False
      ShowVerticalGrid=   -1  'True
      TitleFontColor  =   10485760
      ValueIsNull     =   -1  'True
      BeginProperty DayFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   8.26
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty GridFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty TitleFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   12.01
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.ComboBox cboTDStatus 
      Height          =   315
      ItemData        =   "frmTD.frx":1272
      Left            =   5325
      List            =   "frmTD.frx":1282
      TabIndex        =   1
      TabStop         =   0   'False
      Top             =   2400
      Width           =   1065
   End
   Begin VB.TextBox f24 
      Height          =   315
      Left            =   1800
      TabIndex        =   0
      TabStop         =   0   'False
      Top             =   2400
      Width           =   1065
   End
   Begin VB.CommandButton cmdAddTD 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0E0FF&
      Caption         =   "Add"
      Height          =   315
      Left            =   375
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   2925
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin VB.CommandButton cmdDeleteTD 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0E0FF&
      Caption         =   "Delete"
      Height          =   315
      Left            =   5160
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   2925
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin VB.CommandButton cmdConfirmTD 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0E0FF&
      Caption         =   "Confirm"
      Height          =   315
      Left            =   3525
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   2925
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin VB.CommandButton cmdClose 
      Appearance      =   0  'Flat
      BackColor       =   &H00E0E0E0&
      Caption         =   "OK"
      Height          =   315
      Left            =   6750
      MaskColor       =   &H0080C0FF&
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   2925
      UseMaskColor    =   -1  'True
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Add/Modify TD Shipments"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000080FF&
      Height          =   2115
      Left            =   150
      TabIndex        =   8
      Top             =   150
      Width           =   7815
      Begin MSDataGridLib.DataGrid grdTD 
         Height          =   1515
         Left            =   180
         TabIndex        =   7
         ToolTipText     =   "Click to choose a TD master"
         Top             =   360
         Width           =   7455
         _ExtentX        =   13150
         _ExtentY        =   2672
         _Version        =   393216
         AllowUpdate     =   0   'False
         HeadLines       =   1
         RowHeight       =   15
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
   End
   Begin VB.Timer timerAutoOpen 
      Enabled         =   0   'False
      Interval        =   200
      Left            =   7320
      Top             =   2400
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00FFFFFF&
      Caption         =   "Status:"
      Height          =   315
      Index           =   43
      Left            =   4575
      TabIndex        =   11
      Top             =   2475
      Width           =   615
   End
   Begin VB.Label Label1 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00FFFFFF&
      Caption         =   "Ship Date:"
      Height          =   315
      Index           =   44
      Left            =   825
      TabIndex        =   10
      Top             =   2475
      Width           =   915
   End
   Begin VB.Image Image1 
      Height          =   390
      Left            =   2925
      Picture         =   "frmTD.frx":12A5
      Stretch         =   -1  'True
      Top             =   2400
      Width           =   390
   End
End
Attribute VB_Name = "frmTD"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit

Dim m_rsTD As ADODB.Recordset     'Module level recordset tied to grdTD
Dim m_rsAutoClose As ADODB.Recordset     'Module level recordset
Dim m_rsAutoOpen As ADODB.Recordset     'Module level recordset
Dim m_dtTDDate As Date
Dim m_dtAutoOpen As Date
'

Public Sub AutoClose()

    ' 2011-04-12, JFW,
    timerAutoClose.Enabled = True

End Sub
'

Public Sub AutoOpen(dtTDDate As Date)

    DebugPrint "frmTD.AutoOpen, " & "TDAutoOpen"

    ' 2011-04-12, JFW,
    m_dtTDDate = dtTDDate
    Me.Show 0
    timerAutoOpen.Enabled = True

End Sub
'

Private Sub cboTDStatus_Click()
    
    Call UpdateTDGrid(cboTDStatus, f24)
    
End Sub

Private Sub cmdADDTD_Click()
    
    On Error GoTo ErrorExit
    
    g_blnTDInProgress = False
    g_blnTDConfirm = False
    g_blnTDCreate = True
    g_strTDOpenShip = ""
    g_strTDMasterTrkNbr = ""
    g_dteTDDate = #1/1/2001#
    
    g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
    g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
    g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
    
    Set g_frmTDAdd = New frmTDAdd
    g_frmTDAdd.Caption = "TD Create Shipment"
    g_strErrorLocation = ""
    g_frmTDAdd.Show 1, Me
    Exit Sub
    
ErrorExit:
    frmMsgBox.ShowMessage "Error in AddTD, " & Err.Source & ", " & Err.Description, 4000

End Sub

Private Sub cmdClose_Click()
    On Error Resume Next
    Me.Hide
    frmShip.SetFocus
End Sub

Private Sub cmdConfirmTD_Click()
        
    If g_clsReg.GetRegistryValue("CCITarget", "") <> "" Then
        Call Shell(g_clsReg.GetRegistryValue("CCITarget", ""), vbNormalFocus)
    End If
    
    g_blnTDCreate = False
    g_blnTDConfirm = True
    Set g_frmTDAdd = New frmTDAdd
    g_frmTDAdd.Caption = "TD Confirm Shipment"
    g_frmTDAdd.Show 1, Me
    
End Sub

Private Sub cmdDeleteTD_Click()
    g_blnTDInProgress = True
    Call SendData(BuildTDDeleteTrans(g_strTDMasterTrkNbr, g_str498, g_strTDOpenShip))
End Sub

Private Sub cmdDupTD_Click()
    g_blnTDInProgress = False
    g_blnTDConfirm = False
    g_blnTDCreate = True
    Set g_frmTDAdd = New frmTDAdd
    g_frmTDAdd.Caption = "TD Create Shipment"
    g_frmTDAdd.Show 1, Me
End Sub

Private Sub f24_Validate(Cancel As Boolean)

    If f24 = "" Or IsDate(f24) Then
        Call UpdateTDGrid(cboTDStatus, f24)
    End If

End Sub

'---------------------------------------------------------------------------------------
' Procedure : Form_Activate()
' DateTime  : 10/25/2004
' Purpose   : Call routine to load Commodities into datagrid whenever the form is the
'             active form.
'---------------------------------------------------------------------------------------
'
Private Sub Form_Activate()
    On Error GoTo EH
    g_strErrorLocation = "frmTD:Form_Activate"
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation

End Sub
'---------------------------------------------------------------------------------------
' Procedure : Form_Deactivate()
' DateTime  : 10/25/2004
' Purpose   : Closes module level recordset and sets it to nothing.
'---------------------------------------------------------------------------------------
'
Private Sub Form_Deactivate()
    On Error GoTo EH
    g_strErrorLocation = "frmTD:Form_Deactivate"
    If Not m_rsTD Is Nothing Then
        If m_rsTD.State = adStateOpen Then m_rsTD.Close
    End If
    Set m_rsTD = Nothing
    
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation

End Sub
'---------------------------------------------------------------------------------------
' Procedure : Form_KeyDown()
' DateTime  : 2/17/2005
' Purpose   : Enter key pressed sends a TAB to move to next field
'---------------------------------------------------------------------------------------
'
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Not TypeOf Me.ActiveControl Is CommandButton Then
        If Shift = 0 And KeyCode = 13 Then
            SendKeys "{TAB}"
        End If
    End If
End Sub

Private Sub Form_Load()
    
    Calendar1.Today
    Calendar1.Height = 2295 'Ship date - Ship Tab
    Calendar1.Width = 3015
    Call UpdateTDGrid("Open", "")
    
End Sub


Private Sub Form_Unload(Cancel As Integer)
    Set g_frmTDAdd = Nothing
End Sub


Private Sub grdTD_Click()
    timerMaster.Enabled = True
End Sub

Private Sub grdTD_SelChange(Cancel As Integer)
    timerMaster.Enabled = True
End Sub

'---------------------------------------------------------------------------------------
' Module    : Image1_Click()
' DateTime  : 10/25/2004
' Author    : Chris Elwell
' Purpose   : Show the ShipDate calendar
'---------------------------------------------------------------------------------------
'
Private Sub Image1_Click()
    Calendar1.Visible = True
End Sub

'---------------------------------------------------------------------------------------
' Procedure : Calendar1_Click()
' DateTime  : 10/25/2004
' Purpose   : Puts date selected on calendar in ShipDate field and updates the TD Grid.
'---------------------------------------------------------------------------------------
'
Private Sub Calendar1_DblClick()
    
    f24 = Calendar1.Value
    Calendar1.Visible = False
    Call UpdateTDGrid(cboTDStatus, f24)

End Sub

'---------------------------------------------------------------------------------------
' Procedure : UpdateTDGrid()
' DateTime  : 10/25/2004
' Purpose   : Update the TD grid and set column headings
' Call from : Form_Activate, cmdDelete_Click
'---------------------------------------------------------------------------------------
'
Public Sub UpdateTDGrid(ByVal strTDStatus As String, ByVal dteShipDate As Variant)
    Dim strQuery As String
    Dim i As Long
    
    On Error GoTo EH
    g_strErrorLocation = "frmTD:UpdateTDGrid"
    
    cboTDStatus = strTDStatus
    If IsDate(dteShipDate) Then
        f24 = CDate(dteShipDate)
    End If
    If timerUpdate.Tag <> "Update" Then
        ' 2005-04-21, JFW, Use Tag here, I found that text would not hold.
        cboTDStatus.Tag = strTDStatus
        If IsDate(dteShipDate) Then
            f24.Tag = CDate(dteShipDate)
        Else
            f24.Tag = ""
        End If
        timerUpdate.Enabled = True
        Exit Sub
    End If
    
    strQuery = "SELECT TDStatus,g_str29,g_str24,OpenShipIndex,g_str25 FROM TD Where MAWB = 1 And g_str10 = " & SingleQuotes(frmSetup.f10)
    
    Select Case strTDStatus
        Case "ALL"
            strQuery = strQuery & " And 1 = 1"
        Case "Open"
            strQuery = strQuery & " And TDStatus = 'Open'"
        Case "Confirmed"
            strQuery = strQuery & " And TDStatus = 'Confirmed'"
        Case "Deleted"
            strQuery = strQuery & " And TDStatus = 'Deleted'"
    End Select
    
    If IsDate(dteShipDate) Then
        strQuery = strQuery & " And g_str24 = '" & Format(dteShipDate, "YYYYMMDD") & "'"
    End If
    
    'If already open, close recordset
    If m_rsTD Is Nothing Then Set m_rsTD = New ADODB.Recordset
    If m_rsTD.State = adStateOpen Then m_rsTD.Close
    'Execute query
    m_rsTD.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic

    Set grdTD.DataSource = m_rsTD
    
    ' Must click to choose a TD master
    If False And Not m_rsTD.EOF Then
        Call SetButtons
    Else
        cmdConfirmTD.Enabled = False
        cmdDeleteTD.Enabled = False
        cmdDupTD.Enabled = False
    End If
    
    With grdTD
        .ClearFields
        .ReBind
        i = 0
        .Columns(i).Caption = "Status"
        i = i + 1
        .Columns(i).Caption = "MAWB Trk#"
        i = i + 1
        .Columns(i).Caption = "Ship Date"
        i = i + 1
        .Columns(i).Caption = "Index"
        i = i + 1
        .Columns(i).Caption = "Reference"
        i = 0
        .Columns(i).Width = 1150
        i = i + 1
        .Columns(i).Width = 1150
        i = i + 1
        .Columns(i).Width = 1150
        i = i + 1
        .Columns(i).Width = 1150
        i = i + 1
        .Columns(i).Width = 1600
    End With
    
Release:
    Set m_rsTD = Nothing
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
    Resume Release
     
End Sub
'---------------------------------------------------------------------------------------
' Module    : SetButtons
' DateTime  : 10/26/2004
' Author    : Chris Elwell
' Purpose   : Enable/disable Confirm and Delete Button
' Call from : grdTD_Click, frmShip.EnableButtons
'---------------------------------------------------------------------------------------
'
Public Sub SetButtons()
    On Error GoTo EH
    
    'Only enable buttons if one row selected, cmdADDTD is enable (Winsock connected), and Status is "Open"
    With grdTD
        If frmShip.wscFXRS.State <> 7 Or .Row < 0 Then
            cmdConfirmTD.Enabled = False
            cmdDeleteTD.Enabled = False
            cmdDupTD.Enabled = False
            g_strTDMasterTrkNbr = ""
            If g_strTDOpenShip <> "" Then
                g_strTDOpenShip = ""
                frmShip.DomIntlScreenLayout
            End If
        ElseIf .Columns(0) <> "Open" Then
            cmdConfirmTD.Enabled = False
            cmdDeleteTD.Enabled = False
            If frmShip.wscFXRS.State = 7 Then
                cmdDupTD.Enabled = True
                g_strTDMasterTrkNbr = .Columns(1)
            Else
                cmdDupTD.Enabled = False
                g_strTDMasterTrkNbr = ""
            End If
            If g_strTDOpenShip <> "" Then
                g_strTDOpenShip = ""
                frmShip.DomIntlScreenLayout
            End If
        Else
            cmdConfirmTD.Enabled = True
            cmdDeleteTD.Enabled = True
            cmdDupTD.Enabled = True
            If g_strTDOpenShip <> .Columns(3) Then
                g_strTDOpenShip = .Columns(3)
                g_strTDMasterTrkNbr = .Columns(1)
                g_dteTDDate = CDate(Format(.Columns(2), "0000-00-00"))
                frmShip.DomIntlScreenLayout
                frmShip.f24 = g_dteTDDate
                ' 2005-05-22, JFW, Button tool tip, was on custom button.
                frmShip.cmdViewTD.ToolTipText = g_strTDMasterTrkNbr & " " & g_dteTDDate
            End If
        End If
    End With
    
    g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
    g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
    g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
    
    Exit Sub
EH:
    MsgBox "Error in setup of TD form, " & Err.Description, vbCritical, g_strErrorLocation
    If False Then
        Resume
    End If
End Sub

Private Sub timerAutoClose_Timer()

    On Error GoTo ErrorExit
    
    Dim i As Long
    Dim rsMeter As ADODB.Recordset     'Module level recordset
    Dim rsTDChildren As ADODB.Recordset     'Module level recordset
    
    If m_rsAutoClose Is Nothing Then
        DebugPrint "AutoClose, Recordset"
        Set m_rsAutoClose = New ADODB.Recordset
        m_rsAutoClose.Open "SELECT TDStatus, g_str29, g_str24, OpenShipIndex, g_str25, LocationName FROM TD " _
                        & "Where MAWB = 1 And TDStatus = 'Open'" _
                        , g_connFSMSClient, adOpenStatic, adLockReadOnly
        
    ElseIf Not (m_rsAutoClose.BOF Or m_rsAutoClose.EOF) Then
        DebugPrint "AutoClose, Next"
        If m_rsAutoClose!g_str24 <= Format(Date, "YYYYMMDD") Then
            DebugPrint "AutoClose, date " & m_rsAutoClose!g_str24 & " master " & m_rsAutoClose!g_str29
            Set rsMeter = New ADODB.Recordset
            rsMeter.Open "SELECT Name, f498, f10 FROM Meters " _
                        & "Where Name = " & SingleQuotes(m_rsAutoClose!LocationName) _
                        , g_connFSMSClient, adOpenStatic, adLockReadOnly
            If rsMeter.BOF Or rsMeter.EOF Then Err.Raise 12345, "TD.AutoClose", "Master Shipment " & m_rsAutoClose!g_str29 & ", Location " & m_rsAutoClose!LocationName & ", meter not found."
            g_blnTDInProgress = True
            
            Set rsTDChildren = New ADODB.Recordset
            rsTDChildren.Open "SELECT g_str29 FROM TD " _
                        & "Where MAWB = 0 And OpenShipIndex = " & SingleQuotes(m_rsAutoClose!OpenShipIndex) & " And TDStatus = 'Open'" _
                        , g_connFSMSClient, adOpenStatic, adLockReadOnly
            If rsTDChildren.BOF Or rsTDChildren.EOF Then
                Call SendData(BuildTDDeleteTrans(m_rsAutoClose!g_str29, rsMeter!f498, m_rsAutoClose!OpenShipIndex))
            Else
                Call SendData(BuildTDConfirmTrans(rsMeter!f498, m_rsAutoClose!OpenShipIndex))
                g_blnTDConfirm = False
            End If
            
        End If
        m_rsAutoClose.MoveNext
        
    Else
        DebugPrint "AutoClose, Done"
        Set m_rsAutoClose = Nothing
        timerAutoClose.Enabled = False
    End If
    Exit Sub
    
ErrorExit:
    Set m_rsAutoClose = Nothing
    timerAutoClose.Enabled = False

End Sub

Private Sub timerAutoOpen_Timer()

    On Error GoTo ErrorExit
    
    Dim i As Long
    Dim rsMeter As ADODB.Recordset     'Module level recordset
    Dim rsTDChildren As ADODB.Recordset     'Module level recordset
    
    If m_rsAutoOpen Is Nothing Then
        DebugPrint "AutoOpen, Open"
        Me.Show 0
        Set m_rsAutoOpen = New ADODB.Recordset
        m_rsAutoOpen.Open "SELECT TDStatus, g_str29, g_str24, OpenShipIndex, g_str25, LocationName FROM TD " _
                        & "Where MAWB = 1 And TDStatus = 'Open'" _
                        , g_connFSMSClient, adOpenStatic, adLockReadOnly
        
    ElseIf Not (m_rsAutoOpen.BOF Or m_rsAutoOpen.EOF) Then
        Debug.Assert False
        DebugPrint "AutoOpen, Next"
        If m_rsAutoOpen!g_str24 = Format(m_dtTDDate, "YYYYMMDD") Then
            DebugPrint "AutoOpen, date " & m_rsAutoOpen!g_str24 & " master " & m_rsAutoOpen!g_str29
            Set rsMeter = New ADODB.Recordset
            rsMeter.Open "SELECT Name, f498, f10 FROM Meters " _
                        & "Where Name = " & SingleQuotes(m_rsAutoOpen!LocationName) _
                        , g_connFSMSClient, adOpenStatic, adLockReadOnly
            If rsMeter.BOF Or rsMeter.EOF Then
                Err.Raise 12345, "TD.AutoOpen", "Master Shipment " & m_rsAutoOpen!g_str29 & ", Location " & m_rsAutoOpen!LocationName & ", meter not found."
            End If
            
            ' Set g values here
            g_strTDOpenShip = m_rsAutoOpen!g_str24
            g_strTDMasterTrkNbr = m_rsAutoOpen!g_str24
            g_dteTDDate = m_rsAutoOpen!g_str24
            g_clsReg.SetRegistryValue "TDMasterShipmentID", g_strTDMasterTrkNbr, REG_SZ
            g_clsReg.SetRegistryValue "TDMasterShipmentDate", Format(g_dteTDDate, "yyyy-mm-dd"), REG_SZ
            g_clsReg.SetRegistryValue "TDOpenShipIndex", g_strTDOpenShip, REG_SZ
        End If
        m_rsAutoOpen.MoveNext
        
    ElseIf g_dteTDDate <> m_dtTDDate Or g_strTDOpenShip = "" Or g_strTDMasterTrkNbr = "" Then
        If g_frmTDAdd Is Nothing Then
            m_dtAutoOpen = Now
            g_blnTDInProgress = False
            g_blnTDConfirm = False
            g_blnTDCreate = True
            g_strTDOpenShip = ""
            g_strTDMasterTrkNbr = ""
    
            Set g_frmTDAdd = New frmTDAdd
            g_frmTDAdd.Caption = "TD Create Shipment"
            g_strErrorLocation = ""
            g_frmTDAdd.AutoOpen (m_dtTDDate)
        ElseIf Now > DateAdd("s", 20, m_dtAutoOpen) Then
            Err.Raise 12345, "AutoOpen", "Timeout expired on open of TD Master."
        End If
        
    Else
        DebugPrint "AutoOpen, Done"
        GoTo ExitHere
    
    End If
    Exit Sub
    
ErrorExit:
    g_strErrorLocation = Err.Source & ", " & Err.Description
    MsgBox g_strErrorLocation
ExitHere:
    On Error Resume Next
    Unload g_frmTDAutoOpen
    Set g_frmTDAutoOpen = Nothing
    Set m_rsAutoOpen = Nothing
    timerAutoOpen.Enabled = False

End Sub

Private Sub timerMaster_Timer()
    timerMaster.Enabled = False
    Call SetButtons
End Sub

Private Sub timerUpdate_Timer()

    timerUpdate.Enabled = False
    timerUpdate.Tag = "Update"
    Call UpdateTDGrid(cboTDStatus.Tag, f24.Tag)
    timerUpdate.Tag = ""
    
End Sub
